import rule from './rule'
import tip from './tip'

export default (names, ctx) => {
  const _tip = tip()
  if (!names) {
    _tip.clear()
    return
  }
  return names.some(name => {

    let { value, el } = ctx

    if (!el) {
      value = ctx.state[name]
      el = ctx.refs[name]
    }

    const ret = rule[name].regex.test(value)
    if (!ret) {
      if (!value.trim()) _tip(el, '不能为空', name)
      else {
        _tip(el, rule[name].msg, name)
      }
    } else {
      _tip.destroy(name)
    }
    return !ret
  })
}
